package com.test.account;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

public class Account {
    private int num;
    Lock lock;
    Condition condition;
    public Account(int num) {
        this.num = num;
    }
    public void deposit(int money) {
        lock.lock();
        this.num += money;
        condition.signalAll();
        lock.unlock();
    }
    public void withdraw(int money) {
        lock.lock();
        if (this.num < money) {
            try {
                condition.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.num -= money;
        lock.unlock();
    }
    public int getNum() {
        return this.num;
    }
}
